package com.by.autoconfig;

import com.by.interceptor.LoginInterceptor;
import com.by.interceptor.config.LoginInterceptorConfig;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

/**
 * 登录拦截器自动配置类
 */
@AutoConfiguration(after = {TokenAutoConfiguration.class})
/**
 * 开启属性批量绑定
 */
@EnableConfigurationProperties({LoginInteceptorProperties.class})
/**
 * 增加开关属性 默认情况下  引入当前启动器  登录拦截器自动生效 ，通过token.interceptor.enabled=false关闭拦截器
 */
@ConditionalOnProperty(
        prefix = "token.interceptor",
        name = {"enabled"},
        matchIfMissing = true
)
public class LoginIntectproAutoConfiguration {

    /**
     * 向ioc容器注入LoginInterceptorConfig, 然后注册登录拦截器
     *
     * @return
     */
    @Bean
    public LoginInterceptorConfig interceptorConfig() {
        return new LoginInterceptorConfig();
    }

    @Bean
    public LoginInterceptor loginInterceptor(){
        return new LoginInterceptor();
    }

}
